home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Original Code / Buttons and Labels and Scrolls (Oh, My!) / TwoButtonsDock / TwoButtonsDock.cs next >
Encoding:
Text File  |  2001-01-15  |  1.4 KB  |  48 lines

  1. //---------------------------------------------
  2. // TwoButtonsDock.cs ⌐ 2001 by Charles Petzold
  3. //---------------------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.Windows.Forms;
  7.  
  8. class TwoButtonsDock: Form
  9. {
  10.      public static void Main()
  11.      {
  12.           Application.Run(new TwoButtonsDock());
  13.      }
  14.      public TwoButtonsDock()
  15.      {
  16.           Text = "Two Buttons with Dock";
  17.           ResizeRedraw = true;
  18.  
  19.           Button btn = new Button();
  20.           btn.Parent = this;
  21.           btn.Text   = "&Larger";
  22.           btn.Height = 2 * Font.Height;
  23.           btn.Dock   = DockStyle.Top;
  24.           btn.Click += new EventHandler(ButtonLargerOnClick);
  25.           
  26.           btn = new Button();
  27.           btn.Parent = this;
  28.           btn.Text   = "&Smaller";
  29.           btn.Height = 2 * Font.Height;
  30.           btn.Dock   = DockStyle.Bottom;
  31.           btn.Click += new EventHandler(ButtonSmallerOnClick);
  32.      }
  33.      void ButtonLargerOnClick(object obj, EventArgs ea)
  34.      {
  35.           Left   -= (int)(0.05 * Width);
  36.           Top    -= (int)(0.05 * Height);
  37.           Width  += (int)(0.10 * Width);
  38.           Height += (int)(0.10 * Height);
  39.      }
  40.      void ButtonSmallerOnClick(object obj, EventArgs ea)
  41.      {
  42.           Left   += (int)(Width  / 22f);
  43.           Top    += (int)(Height / 22f);
  44.           Width  -= (int)(Width  / 11f);
  45.           Height -= (int)(Height / 11f);
  46.      }
  47. }
  48.